﻿using System;
using System.Collections.Generic;
using Domino;

namespace NotesCommonProjects
{
    public class SendMailCF
    {
        /// <summary>檢查收到的NewNotesDocument物件屬性是否有缺少</summary>
        /// <param name="doc">傳入的Json物件反序列化成NewNotesDocument物件</param>
        /// <returns>檢查是否合法</returns>
        public static bool CheckReceiveObject(NewNotesDocument doc)
        {
            if (string.IsNullOrEmpty(doc.Server) || string.IsNullOrEmpty(doc.Database) || string.IsNullOrEmpty(doc.Form)
                 || string.IsNullOrEmpty(doc.View) || string.IsNullOrEmpty(doc.Key))
                return false;
            else
                return true;

        }

        /// <summary>將值填入每個NotesDocument欄位</summary>
        /// <param name="NotesDoc">NotesDocument物件</param>
        /// <param name="EmailObject">NewNotesDocument物件</param>
        public static void InsertNewValueIntoNotesDocument(NotesDocument NotesDoc, NewNotesDocument EmailObject)
        {
            foreach (NewNotesItem i in EmailObject.Items)
            {
                NotesDoc.ReplaceItemValue(i.Name, i.Value);
            }
        }

        /// <summary>取得測試NewNotesDocument物件</summary>
        /// <returns>測試物件：品檢單AP</returns>
        public static NewNotesDocument GetDummyQCObject()
        {
            List<NewNotesItem> DummyEflds = new List<NewNotesItem>();
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "COMPANY",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "FIRM",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "ORD_NO",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "PRD_PC",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "CUST_NAME",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "PRE_DATE",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "SALE",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "TKEY",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "HPD",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "PDATE",
                Value = "Test"
            });
            DummyEflds.Add(new NewNotesItem()
            {
                Name = "XLSNAME",
                Value = @"Test"
            });

            NewNotesDocument DummyEmail = new NewNotesDocument()
            {
                Server = "TNOTES01/T/CCP",
                Database = "QC",
                Form = "FQ5",
                View = "VQ5",
                //Key = "T1580400001-2",     //文件存在
                //Key = "Test",    //文件不存在
                Key = "Test2",     //文件不存在
                AttachmentPath = @"C:\\temp.xls",
                Items = DummyEflds

            };

            return DummyEmail;
        }
    }

    public class NewNotesDocument
    {
        public string Server { get; set; }
        public string Database { get; set; }
        public string Form { get; set; }
        public string View { get; set; }
        public string Key { get; set; }
        public string AttachmentPath { get; set; }

        public List<NewNotesItem> Items { get; set; }
    }

    public class NewNotesItem
    {
        public string Name { get; set; }
        public object Value { get; set; }
    }
}